package 回显服务器;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:翻译服务器
 * User: lenovo
 * Date: 2022-10-18
 * Time: 10:44
 */
public class UdpTranslateServe extends UDPEchoServe1{//继承回显服务器,实现代码复用
    //map k-v模型
    Map<String,String> transl = new HashMap<>();
    public UdpTranslateServe(int port) throws SocketException {
        super(port);
        //往hash表里添加元素
        transl.put("小猫","cat");
        transl.put("小狗","dog");
    }
    //根据请求计算响应,逻辑不同,需要重写
    @Override
    public String process(String requst) {
        return transl.getOrDefault(requst,"服务器里没有这个词");
    }
    //start方法一样,不需要重写

    public static void main(String[] args) throws IOException {
        UdpTranslateServe translateServe = new UdpTranslateServe(9090);
        translateServe.start();
    }

}
